﻿#ifndef ENUM_SERIALIZATION_H
#define ENUM_SERIALIZATION_H

#include "engine_types.h"
#include "engine_device_manager.h"
#include "engine_audio_mixing_manager.h"
#include <QJsonValue>
#include <QDebug>


using namespace ding::rtc;

// 宏定义：为枚举类型生成序列化和反序列化函数
#define ENUM_SERIALIZATION(EnumType)                                                   \
    static QJsonValue s##EnumType(const EnumType& value) {                             \
        return QJsonValue(static_cast<int>(value));                                    \
    }                                                                                  \
                                                                                       \
    static EnumType des##EnumType(const QJsonValue& jsonValue) {                       \
        if (!jsonValue.isDouble()) {                                                   \
            qWarning() << "Invalid JSON value for enum deserialization:" << jsonValue; \
            return static_cast<EnumType>(0); /* 返回默认值 */                          \
        }                                                                              \
        return static_cast<EnumType>(jsonValue.toInt());                               \
    }

// 为所有枚举类型使用宏生成函数
ENUM_SERIALIZATION(RtcEngineUserOfflineReason)
ENUM_SERIALIZATION(RtcEngineOnByeType)
ENUM_SERIALIZATION(RtcEngineConnectionStatus)
ENUM_SERIALIZATION(RtcEngineConnectionStatusChangeReason)
ENUM_SERIALIZATION(RtcEngineNetworkQuality)
ENUM_SERIALIZATION(RtcEngineLogLevel)
ENUM_SERIALIZATION(RtcEngineErrorCode)
ENUM_SERIALIZATION(RtcEngineRenderMode)
ENUM_SERIALIZATION(RtcEngineRenderMirrorMode)
ENUM_SERIALIZATION(RtcEngineVideoScale)
ENUM_SERIALIZATION(RtcEngineRotationMode)
ENUM_SERIALIZATION(RtcEngineAudioTrack)
ENUM_SERIALIZATION(RtcEngineAudioFrameType)
ENUM_SERIALIZATION(RtcEngineVideoTrack)
ENUM_SERIALIZATION(RtcEngineVideoStreamType)
ENUM_SERIALIZATION(RtcEngineSubscribeState)
ENUM_SERIALIZATION(RtcEngineCaptureOutputPreference)
ENUM_SERIALIZATION(RtcEngineCameraDirection)
ENUM_SERIALIZATION(RtcEngineVideoEncoderOrientationMode)
ENUM_SERIALIZATION(RtcEngineVideoMirrorMode)
ENUM_SERIALIZATION(RtcEngineVirtualBackgroundMode)
ENUM_SERIALIZATION(RtcEngineVideoEnhanceMode)
ENUM_SERIALIZATION(RtcEngineVideoDenoiseMode)
ENUM_SERIALIZATION(RtcEngineAudioDenoiseMode)
ENUM_SERIALIZATION(RtcEngineScreenShareType)
ENUM_SERIALIZATION(RtcEnginePublishState)
ENUM_SERIALIZATION(RtcEngineVideoFrameType)
ENUM_SERIALIZATION(RtcEngineVideoPixelFormat)
ENUM_SERIALIZATION(RtcEngineVideoObservePosition)
ENUM_SERIALIZATION(RtcEngineAudioProfile)
ENUM_SERIALIZATION(RtcEngineAudioScenario)
ENUM_SERIALIZATION(RtcEngineAudioObservePosition)
ENUM_SERIALIZATION(RtcEngineAudioNumChannelType)
ENUM_SERIALIZATION(RtcEngineAudioSampleRate)
ENUM_SERIALIZATION(RtcEngineAudioFramePermissions)
ENUM_SERIALIZATION(RtcEngineRecordMode)
ENUM_SERIALIZATION(RtcEngineRecordStatusCode)
ENUM_SERIALIZATION(RtcEngineRecordLayoutMode)
ENUM_SERIALIZATION(RtcEngineDeviceType)
ENUM_SERIALIZATION(RtcEngineDeviceState)
ENUM_SERIALIZATION(RtcEngineAudioMixingStatus)
ENUM_SERIALIZATION(RtcEngineAudioMixingErrorCode)

#endif // ENUM_SERIALIZATION_H
